package com.one.group.user.lister;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class RabbitCacheListener {
//    @RabbitListener(bindings = @QueueBinding(
//            value = @Queue(name = "doctor.queue"),
//            exchange = @Exchange(name = "cache.direct", type = ExchangeTypes.DIRECT),
//            key = {"doctor"}
//    ))
//    public void listenCacheDoctor(){
//        log.info("监听到删除缓存消息,删除缓存:{}");
//    }
    @Autowired
    private RedisTemplate redisTemplate;
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "cache.direct2"),
            exchange = @Exchange(name = "gxa.direct", type = ExchangeTypes.DIRECT),
            key = {"deleteCell"}
    ))
    public void listenCacheCell(Long id){
        log.info("监听到删除缓存消息,删除缓存:"+"cellId"+ id);
        redisTemplate.delete("cell:"+id);
    }
}